package com.heima.wemedia.controller.v1;


import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.common.dtos.WmNewsDto;
import com.heima.model.common.dtos.WmNewsPageReqDto;
import com.heima.model.common.enums.AppHttpCodeEnum;
import com.heima.model.common.pojos.wemedia.WmNews;
import com.heima.wemedia.service.WmNewsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/news")
@Slf4j
public class WmNewsController {
    @Autowired
    private WmNewsService wmNewsService;

    /**
     * 查询文章内容列表
     * @param wmNewsPageReqDto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmNewsPageReqDto wmNewsPageReqDto){
        log.info("查询文章内容列表：{}", wmNewsPageReqDto);
        return wmNewsService.pageQuery(wmNewsPageReqDto);
    }

    /**
     * 发布文章
     * @param wmNewsDto
     * @return
     */
    @PostMapping("/submit")
    public ResponseResult submit(@RequestBody WmNewsDto wmNewsDto){
        log.info("发布文章：{}",wmNewsDto);
        return wmNewsService.submit(wmNewsDto);
    }

    /**
     * 查看详情
     * @param id
     * @return
     */
    @GetMapping("/one/{id}")
    public ResponseResult getById(@PathVariable Integer id){
        log.info("根据id查询文章详情：{}",id);
        return wmNewsService.selectById(id);
    }

    /**
     * 上下架
     * @param
     * @return
     */
    @PostMapping("/down_or_up")
    public ResponseResult DownOrUp(@PathVariable Integer id ){
        log.info("文章上下架：{}", id);

        return wmNewsService.downOrUp(id);
    }

    /**
     * 删除文章
     * @param id
     * @return
     */
    @GetMapping("/del_news/{id}")
    public ResponseResult delete(@PathVariable Integer id){
        log.info("删除文章：{}",id);
        wmNewsService.delete(id);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
